--- 战策四·反守为攻
local policy4 = fk.CreateSkill {
    name = "reverse_attack",
    tags = { Skill.Compulsory },
    dynamic_name = function (self, player, lang)
      return player == Self and self.name or "unknownpolicy"
    end,
    dynamic_desc = function (self, player, lang)
      return player == Self and self.name or "unknownpolicy"
    end,
}

local HG = require "packages.new_heg_diy_my.util"

Fk:loadTranslationTable {
    ["@[reverse_attack_mark]"] = "反守为攻",
    ["reverse_attack_ask"] = "战策-反守为攻：你可以视为对此牌使用者使用一张【杀】",
}

local skill_spec = {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        local mark_name = "@[private]" .. policy4.name .. "_mark"
        return player:getMark(mark_name) ~= 0 and target == player and data.responseToEvent and data.responseToEvent.card and data.responseToEvent.from
        and data.responseToEvent.from ~= player and not data.responseToEvent.from.dead and player:canUseTo(Fk:cloneCard("slash"), data.responseToEvent.from, {bypass_distances = true, bypass_times = true})
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player, { skill_name = "unknownpolicy", prompt = "reverse_attack_ask" })
    end,
    on_use = function(self, event, target, player, data)
        local mark_name = "@[private]" .. policy4.name .. "_mark"
        local room = player.room
        local to = data.responseToEvent.from
        if to and to.dead then return end
        room:useVirtualCard("slash", nil, player, to, policy4.name, true)
        room:setPlayerMark(player, mark_name, 0)
        room:handleAddLoseSkills(player, "-reverse_attack", nil, false)
        room.logic:trigger(HG.HegLosePolicy, player, { player, policy4.name })
        local card = Fk:cloneCard("heg_reverse_attack")
        room:getVirtCardId(card)
        room:showVirtualCard(card, player, nil, room.logic:getCurrentEvent().id + 1)
    end,
}

policy4:addEffect(fk.CardUseFinished, skill_spec)
policy4:addEffect(fk.CardRespondFinished, skill_spec)

return policy4
